//get_everywhere_coupon
//领取兑换券
exports.get_exchange_coupon = function (req, res) {

    var bodyParams = req.routeInfo.bodyParams;
    //最终结果
    var resultData = {};

    //任务流创建
    async.waterfall([

            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.search_user_exchange_coupon +"/uec_uid/"+bodyParams.u_id+"/uec_ecid/"+bodyParams.coupon_id+"/uec_oid/"+bodyParams.oid,
                        method: 'POST',
                        data: {
                            fields:["uec_id"].join(",")
                        }
                    },
                    function (err, data) {
                        //判断是否有错误信息
                        if (err) {
                            return RES.response(res, false, data);
                        }
                        var is_get = data.data;
                        if(is_get.length>0){
                            return RES.response(res, false, "您已经领取过啦");
                        }else{
                            cb();
                        }
                    }
                );
            },
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.add_exchange_coupon,
                        method: 'POST',
                        data: {
                            uec_uid: bodyParams.u_id,
                            uec_ecid: bodyParams.coupon_id,
                            uec_oid: bodyParams.oid
                        }
                    },
                    function (err, data) {
                        //判断是否有错误信息
                        if (err) {
                            return RES.response(res, false, data);
                        }
                        resultData.addData = data.data;
                        cb();
                    }
                );
            },

        ], function (err, result) {

            //返回最终拼接结果
            RES.response(res, true, resultData);

        }
    );

};